package main

import (
	"html/template"
	"os"
)

type Movies struct {
	Title  string
	Year   int  `json:"released"`
	Color  bool `json:"color,omitempty"`
	Actors []string
}

func main() {
	var movies = []Movies{
		{Title: "Casablance", Year: 1942, Color: false, Actors: []string{"Hum", "Ingrid"}},
		{Title: "Cool Hand Luke", Year: 1967, Color: true, Actors: []string{"Paul"}},
		{Title: "KongFu", Year: 1968, Color: true, Actors: []string{"chenglong"}},
	}
	const tepl = `
电影名:{{.Title | hello}}
年份是:{{.Year}}		  
颜色是:{{.Color | print}}
演员有:{{.Actors}}
		`
	report := template.Must(template.New("report").Funcs(template.FuncMap{"hello": hello, "print": print}).Parse(tepl))
	for _, v := range movies {
		report.Execute(os.Stdout, v)
	}
}

func hello(word string) string {
	return "《" + word + "》"
}

func print(color bool) string {
	if color {
		return "彩色"
	}
	return "黑白"
}
